﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManageSystem
{
    public partial class AddType : Form
    {
        public AddType()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string commend = "select * from bookType where typeName='" + this.textBox1.Text + "'";
            SqlDataReader dataReader = Utils.getDataReader(commend);
            if (dataReader.Read())
            {
                MessageBox.Show("该类型已存在，请修改类型名！");
                textBox1.Focus();
                return;
            }
            string str = "insert into bookType (typeName) values(N'" + textBox1.Text + "')";
            if (Utils.ExecuteNoQuery(str) != -1)
            {
                ManageBookType a = (ManageBookType)this.Owner;
                a.updateData();
                MessageBox.Show("添加成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
